package com.kai.prc.consummer;

import com.kai.annotation.Service;
import com.kai.dto.RPCCommonReqDTO;
import com.kai.dto.UserDto;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author kai
 * @date 2021/3/20 9:28
 * @description:
 */
public class PRCInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy ");
        UserDto userDto = new UserDto();
        userDto.setName("123");
        userDto.setAge(123);


        RPCCommonReqDTO rpcCommonReqDTO = new RPCCommonReqDTO();

        rpcCommonReqDTO.setArga(args);
        rpcCommonReqDTO.setMethodName(method.getName());
        rpcCommonReqDTO.setClassPath("com.kai.rpc.provider.service.impl.UserServiceImpl");


        rpcCommonReqDTO.setClassPath(method.getDeclaringClass().getAnnotation(Service.class).value());



        Object response = NetClient.callRemoteService("localhost", 9999, rpcCommonReqDTO);

        return response;
    }
}
